package com.kingyea.mobilepolice.util;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cxc
 * @version v1.0.0
 * @description This is a class
 * @date Created in 2018.04.13 11:55
 */

public class JsonUtils {

    /**
     * @Description: map 转 bean
     * @Param: [map, clazz]
     * @return: T
     * @Author: cxc
     * @Date: 2018.04.13 11:56
     */
    public static <T> T mapToBean(Map<?, ?> map, Class<T> clazz) {
        return JSON.parseObject(JSON.toJSONString(map), clazz);
    }

    public static <K, V> Map<K, V> beanToMap(Object obj, Class<K> k, Class<V> v) {
        return JSON.parseObject(JSON.toJSONString(obj), new HashMap<K, V>().getClass());
    }
}
